package com.link.gateway.core.filter.visitstatistics.util;

import java.util.List;
import java.util.Map;

/**
 * 用于存放接口访问配置信息的类
 *
 * @author LiYang
 * @date 20190823
 */
public class VisitConfigSingleton {

    private static volatile VisitConfigSingleton instance;

    public static VisitConfigSingleton getInstance() {
        if (null == instance) {
            synchronized (VisitConfigSingleton.class) {
                if (null == instance) {
                    instance = new VisitConfigSingleton();
                }
            }
        }
        return instance;
    }

    private VisitConfigSingleton() {
    }

    private String luaScript = "local key = KEYS[1]\n"
            + "local limit = tonumber(ARGV[1])\n"
            + "local current = tonumber(redis.call('get', key) or \"0\")\n"
            + "if current + 1 > limit then\n"
            + "\treturn 0\n"
            + "else\n"
            + "\tredis.call(\"INCRBY\", key, \"1\")\n"
            + "\tredis.call(\"expire\", key, \"60\")\n"
            + "\treturn 1\n"
            + "end";

    /**
     * 功能状态
     * */
    private String status = "N";

    /**
     * 频率时间范围
     * */
    private String limitTime = "1";

    /**
     * 单位时间预警请求数量
     * */
    private String limitVisitNum = "500";

    /**
     * 单位时间越权请求数量
     * */
    private String limitAuthNum = "500";

    /**
     * 是否发送短信预警
     * */
    private String msgAlert = "N";

    /**
     * 是否发送邮件预警
     * */
    private String emailAlert = "N";

    /**
     * 短信模板编码
     * */
    private String msgExampleCode;

    /**
     * 短信参数
     * */
    private String msgParams;

    /**
     * 短信类型
     * */
    private String msgType;

    /**
     * 短信通知手机号
     * */
    private String msgPhones;

    /**
     * 警报通知时间间隔
     * */
    private String alertTimeInterval = "20";

    /**
     * 通知邮箱
     * */
    private String emailAddrs;

    /**
     * 是否启用访问限制
     * */
    private String accessRestriction = "N";

    /**
     * 查询报表类型，visit/auth，访问/越权
     * */
    private String queryReportType;

    /**
     * 查询报表时间范围 today/thisMonth/total，今日/本月/累计
     * */
    private String queryReportRange;

    /**
     * 查询报表的url
     * */
    private String queryReportUrl;

    private List<String> urls;
    /** 不
     * 记录的接口
     * */
    private Map<String, Boolean> noRecord;

    /**
     * 特殊记录的url
     * */
    private Map<String, Boolean> specialUrl;

    /**
     * 特殊url的时间间隔
     * */
    private String specialLimitTime = "1";

    /**
     * 特殊url的访问数量限制
     * */
    private String specialLimitNum = "500";

    /**
     * 特殊url的越权数量限制
     * */
    private String specialAuthNum = "500";

    /**
     * 登录请求限制次数
     * */
    private String loginLimitNum = "500";

    /**
     * 登录请求限制单位时间
     * */
    private String loginLimitTime = "1";

    /**
     * 登录请求下次报警时间间隔
     * */
    private String loginAlertInterval = "20";

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getLimitTime() {
        return limitTime;
    }

    public void setLimitTime(String limitTime) {
        this.limitTime = limitTime;
    }

    public String getLimitVisitNum() {
        return limitVisitNum;
    }

    public void setLimitVisitNum(String limitVisitNum) {
        this.limitVisitNum = limitVisitNum;
    }

    public String getLimitAuthNum() {
        return limitAuthNum;
    }

    public void setLimitAuthNum(String limitAuthNum) {
        this.limitAuthNum = limitAuthNum;
    }

    public String getMsgAlert() {
        return msgAlert;
    }

    public void setMsgAlert(String msgAlert) {
        this.msgAlert = msgAlert;
    }

    public String getEmailAlert() {
        return emailAlert;
    }

    public void setEmailAlert(String emailAlert) {
        this.emailAlert = emailAlert;
    }

    public String getMsgExampleCode() {
        return msgExampleCode;
    }

    public void setMsgExampleCode(String msgExampleCode) {
        this.msgExampleCode = msgExampleCode;
    }

    public String getMsgParams() {
        return msgParams;
    }

    public void setMsgParams(String msgParams) {
        this.msgParams = msgParams;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public String getMsgPhones() {
        return msgPhones;
    }

    public void setMsgPhones(String msgPhones) {
        this.msgPhones = msgPhones;
    }

    public String getAlertTimeInterval() {
        return alertTimeInterval;
    }

    public void setAlertTimeInterval(String alertTimeInterval) {
        this.alertTimeInterval = alertTimeInterval;
    }

    public String getEmailAddrs() {
        return emailAddrs;
    }

    public void setEmailAddrs(String emailAddrs) {
        this.emailAddrs = emailAddrs;
    }

    public String getAccessRestriction() {
        return accessRestriction;
    }

    public void setAccessRestriction(String accessRestriction) {
        this.accessRestriction = accessRestriction;
    }

    public String getQueryReportType() {
        return queryReportType;
    }

    public void setQueryReportType(String queryReportType) {
        this.queryReportType = queryReportType;
    }

    public String getQueryReportRange() {
        return queryReportRange;
    }

    public void setQueryReportRange(String queryReportRange) {
        this.queryReportRange = queryReportRange;
    }

    public String getQueryReportUrl() {
        return queryReportUrl;
    }

    public void setQueryReportUrl(String queryReportUrl) {
        this.queryReportUrl = queryReportUrl;
    }

    public List<String> getUrls() {
        return urls;
    }

    public void setUrls(List<String> urls) {
        this.urls = urls;
    }

    public Map<String, Boolean> getNoRecord() {
        return noRecord;
    }

    public void setNoRecord(Map<String, Boolean> noRecord) {
        this.noRecord = noRecord;
    }

    public Map<String, Boolean> getSpecialUrl() {
        return specialUrl;
    }

    public void setSpecialUrl(Map<String, Boolean> specialUrl) {
        this.specialUrl = specialUrl;
    }

    public String getSpecialLimitTime() {
        return specialLimitTime;
    }

    public void setSpecialLimitTime(String specialLimitTime) {
        this.specialLimitTime = specialLimitTime;
    }

    public String getSpecialLimitNum() {
        return specialLimitNum;
    }

    public void setSpecialLimitNum(String specialLimitNum) {
        this.specialLimitNum = specialLimitNum;
    }

    public String getSpecialAuthNum() {
        return specialAuthNum;
    }

    public void setSpecialAuthNum(String specialAuthNum) {
        this.specialAuthNum = specialAuthNum;
    }

    public String getLoginLimitNum() {
        return loginLimitNum;
    }

    public void setLoginLimitNum(String loginLimitNum) {
        this.loginLimitNum = loginLimitNum;
    }

    public String getLoginLimitTime() {
        return loginLimitTime;
    }

    public void setLoginLimitTime(String loginLimitTime) {
        this.loginLimitTime = loginLimitTime;
    }

    public String getLoginAlertInterval() {
        return loginAlertInterval;
    }

    public void setLoginAlertInterval(String loginAlertInterval) {
        this.loginAlertInterval = loginAlertInterval;
    }
}
